﻿using AppFramework.Logger;
using PerpheralDevice;
using PerpheralDevice.IRepository;
using System.Reflection;
using System.Runtime.CompilerServices;

namespace AppMachine.Domain.LogicCom;

/// <summary>
/// 应用逻辑组件基类
/// </summary>
public abstract class AppComPrim: AppCom {

    public AppComPrim(IPerpDevRepository perpDevRepository, IComConfig comConfig, IComRepository comRepository)
        : base(perpDevRepository, comConfig, comRepository) { }


    public PerpDev PerpDev => this.mfIPerpDevRepository.GetByID<PerpDev>(this.ComConfig.PerpDevID!);

    public string PerpDevID => this.ComConfig.PerpDevID;
    /// <summary>
    /// 设置应用组件的物理外设ID
    /// 原子组件 DI,DO,伺服 才有 对应的 物理外设ID; 其他复杂组件(由原子组件构成的更大粒度的组件)与物理外设是1:N的关系
    /// </summary>
    /// <param name="devID">应用组件对应的物理外设ID</param>
    /// <returns></returns>
    public AppComPrim DevIDSet(string devID) { 
        (this.ComConfig as AppComConfig)!.PerpDevID = devID;
        return this;
    }

    public string PerpUnitID => this.ComConfig.PerpSeatID;
    /// <summary>
    /// 设置应用组件的物理外设单元ID
    /// 原子组件 DI,DO,伺服 才有 对应的 物理外设单元ID; 其他复杂组件(由原子组件构成的更大粒度的组件)与物理外设单元是1:N的关系
    /// </summary>
    /// <param name="unitID">应用组件对应的物理外设单元ID</param>
    /// <returns></returns>
    public AppComPrim UnitIDSet(string unitID) {
        (this.ComConfig as AppComConfig)!.PerpSeatID = unitID;
        return this;
    }

}
